package canglang.monitor.cases.service.impl;

import canglang.monitor.cases.dao.CaseTwoDAO;
import canglang.monitor.cases.model.CaseTwoModel;
import canglang.monitor.cases.model.CaseLightModel;
import canglang.monitor.cases.service.CaseTwoMgr;
import canglang.monitor.cases.service.CaseLightMgr;
import canglang.monitor.cases.to.SearchTwoTO;
import canglang.monitor.core.base.pagination.PaginatedListHelper;
import canglang.monitor.core.base.util.DateUtil;

import java.util.List;
import java.util.Date;

@SuppressWarnings("unchecked")
public class CaseTwoMgrImpl implements CaseTwoMgr {

    private CaseTwoDAO caseTwoDAO;

    private CaseLightMgr caseLightMgr;

    public void setCaseLightMgr(CaseLightMgr caseLightMgr) {
        this.caseLightMgr = caseLightMgr;
    }

    public void setCaseTwoDAO(CaseTwoDAO caseTwoDAO) {
        this.caseTwoDAO = caseTwoDAO;
    }

    public CaseTwoModel addCaseTwo(CaseTwoModel caseTwoModel) {
        int id = caseTwoDAO.addCaseTwo(caseTwoModel);
        CaseLightModel caseLightModel = new CaseLightModel();
        caseLightModel.setCaseType("02");
        caseLightModel.setCaseId(id);
        caseLightModel.setDeptId(caseTwoModel.getDeptId());
        caseLightModel.setPplInd("N");
        caseLightModel.setProcInd("N");        
        caseLightModel.setLightInd("N");
        Date date = DateUtil.getDate();
        caseLightModel.setCreateId(caseTwoModel.getCreateId());
        caseLightModel.setUpdateId(caseTwoModel.getCreateId());
        caseLightModel.setCreateDt(date);
        caseLightModel.setUpdateDt(date);
        caseLightMgr.addCaseLight(caseLightModel);
        return caseTwoDAO.getCaseTwo(id);
    }

    public CaseTwoModel getCaseTwo(int caseTwoId) {
        return caseTwoDAO.getCaseTwo(caseTwoId);
    }

    public CaseTwoModel saveCaseTwo(CaseTwoModel caseTwoModel) {
        caseTwoDAO.saveCaseTwo(caseTwoModel);
        caseLightMgr.updateLightDept("02",caseTwoModel.getCaseTwoId(),caseTwoModel.getDeptId());
        return caseTwoDAO.getCaseTwo(caseTwoModel.getCaseTwoId());
    }

    public void deleteCaseTwo(int caseTwoId) {
        caseLightMgr.deleteUnuseLight("02",caseTwoId);
        caseTwoDAO.deleteCaseTwo(caseTwoId);
    }

    public PaginatedListHelper search(PaginatedListHelper helper, SearchTwoTO searchTO) {
        int count = caseTwoDAO.searchCount(searchTO);
        helper.setFullListSize(count);
        List list = caseTwoDAO.searchList(helper, searchTO);
        helper.setList(list);
        return helper;
    }

    public List getCaseTwoList(SearchTwoTO searchTO) {
        return caseTwoDAO.getCaseTwoList(searchTO);
    }
}
